package com.yingxin.yxerp.module.dingtalk.controller;

import com.yingxin.yxerp.module.dingtalk.config.WeComAppConfig;
import com.yingxin.yxerp.module.dingtalk.dto.WeComUserDto;
import com.yingxin.yxerp.module.dingtalk.service.IWeComUserService;
import com.yingxin.yxerp.module.dingtalk.util.WeComAccessTokenUtil;
import com.yingxin.yxerp.module.dingtalk.util.WeComFileDownloadUtil;
import com.yingxin.yxerp.module.dingtalk.vo.WeComUserRespVo;
import com.yingxin.yxerp.module.dingtalk.vo.we.com.WeComUserDepartmentIdList;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/we/com")
public class WeComTaliController {

    @Autowired
    private IWeComUserService userService;

    @Autowired
    private WeComFileDownloadUtil weComFileDownloadUtil;

    @Autowired
    private WeComAccessTokenUtil weComAccessTokenUtil;

    @Autowired
    private WeComAppConfig appConfig;

    @ApiOperation(value = "测试 - 获取成员和部门id列表")
    @GetMapping("/getuserdeptlist")
    public void getUserDeptlist() {
        List<WeComUserDepartmentIdList> list = userService.getUserIdList();
        List<String> userids = list.stream().map(WeComUserDepartmentIdList::getUserid).distinct().collect(Collectors.toList());
        System.out.println(userids);
    }

    @ApiOperation(value = "测试 - 获取成员信息")
    @GetMapping("/getuser")
    public void getUser() {
        WeComUserDto dto = userService.getByUserId("YueBao");
        System.out.println(dto);
    }

    @ApiOperation(value = "测试 - 获取成员信息")
    @GetMapping("/getrszslist")
    public void getrszslist() {
        List<WeComUserRespVo> list = userService.getPersonnelAssistantList();
    }

    @ApiOperation(value = "测试 - 临时素材下载")
    @GetMapping("/download")
    public Object download() throws Exception {
        String accessToken = weComAccessTokenUtil.getAccessToken( appConfig.getAppCorpId(), appConfig.getAppSecret() );
        return weComFileDownloadUtil.download(
                "https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token="+accessToken+
                        "&media_id=WWME_aj2xDgAAV9-CnkV_ejcoWdnvYymiZg","abcdefg", "123", "234" );
    }



//    @Autowired
//    private WeComAppConfig appConfig;
//
//    @Autowired
//    private WeComMessageNotificationService messageNotificationService;
//
//    @Autowired
//    private WeComAccessTokenUtil weComAccessTokenUtil;
//
//    @ApiOperation(value = "获取token测试")
//    @GetMapping("/token")
//    public void token() {
//        System.out.println( weComAccessTokenUtil.getAccessToken( appConfig.getAppCorpId(), appConfig.getAppSecret() ) );
//    }
//
//    @ApiOperation(value = "上传素材 - 图片")
//    @GetMapping("/uploadFile")
//    public void uploadFile() {
//        String filePath = "C:\\Users\\YueBao\\Pictures\\2.jpg";
//        System.out.println(
//            messageNotificationService.uploadFile( filePath, WeComFileTypeEnums.IMAGE.getType() )
//        );
//    }
//
//    @ApiOperation(value = "上传图片")
//    @GetMapping("/uploadImage")
//    public void uploadImage() {
//        String filePath = "C:\\Users\\YueBao\\Pictures\\1.jpg";
//        System.out.println(
//                messageNotificationService.uploadFile( filePath, WeComFileTypeEnums.IMAGE.getType() )
//        );
//    }
//
//    @ApiOperation(value = "发送文本消息")
//    @GetMapping("/sendTextMsg")
//    public void sendTextMsg() {
//        String content = "测试文本消息";
//        messageNotificationService.sendGroupTextMsg( content, "CHATID" );
//    }
//
//    @ApiOperation(value = "发送图片消息")
//    @GetMapping("/sendImgMsg")
//    public void sendImgMsg() {
//        String filePath = "C:\\Users\\YueBao\\Pictures\\1.jpg";
//        messageNotificationService.sendGroupImgMsg( filePath, "CHATID" );
//    }
//
//    @ApiOperation(value = "发送文件消息")
//    @GetMapping("/sendFileMsg")
//    public void sendFileMsg() {
//        String filePath = "C:\\Users\\YueBao\\Pictures\\火绒终端安全管理系统2.0产品使用说明.pdf";
//        messageNotificationService.sendGroupFileMsg( filePath, "CHATID" );
//    }

}
